import "colors";
import buildConfigs from "./webpack/webpack.build";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const onConfig = (env: any, args: any) => {
  const isDebug = env.WEBPACK_SERVE === true;
  const showConfigs = env.SHOW_CONFIGS === true;
  const configNames: string[] =
    args.configName !== undefined ? (args.configName as string[]) : [];

  // 生产环境
  if (env.production === true) {
    console.log("正在加载生产环境配置...".red.bgWhite.bold);
  }
  // 测试环境
  else if (env.development === true) {
    // do something
    console.log("正在加载开发环境配置...".red.bgWhite.bold);
  }
  // 未知环境
  else {
    throw "未知开发环境！";
  }

  const configs = buildConfigs(env.production === true, isDebug, configNames);

  console.log("环境配置加载完成！".red.bgWhite.bold);
  console.log();

  if (showConfigs) {
    console.log(
      "<-------------------- webpack 配置列表 -------------------->".white.bgRed
        .bold
    );
    console.log(configs);
    console.log(
      "<-------------------- webpack 配置结束 -------------------->".white.bgRed
        .bold
    );
  }


  return configs;
};

export default onConfig;
